class Solution(object):
    def subsetsWithDup(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        result = [[]]
        def build(sub, begin):
            for i in range(begin, len(nums)):
                sub.append(nums[i])
                result.append(sorted(sub))
                build(sub, i+1)
                sub.pop()
        build([], 0)
        result.sort()
        finalResult = [[]]
        for ret in result:
            if ret != finalResult[-1]:
                finalResult.append(ret)
        return finalResult

print(Solution().subsetsWithDup([2,2,1]))
